package com.maktoub.apiinterfaceproject.controller;

import com.maktoub.apiinterfaceproject.common.BaseResponse;
import com.maktoub.apiinterfaceproject.entity.HelloGetListParam;
import com.maktoub.apiinterfaceproject.entity.InputParam;
import com.maktoub.apiinterfaceproject.entity.PostInputParamTest;
import com.maktoub.apiinterfaceproject.exception.BaseException;
import com.maktoub.apiinterfaceproject.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * say Hello接口
 * @author maktoub
 */

@RestController
@RequestMapping("/say")
public class MainController {

    @Autowired
    UserService userService;

    @GetMapping("/test")
    public BaseResponse<String > testInterfaceNodata(@RequestParam(required = false) String name,HttpServletRequest request){
        return new BaseResponse<>(200,"testOk ","");

    }
    @GetMapping("/test_err")
    public BaseResponse<String > testInterfaceNodataErr(@RequestParam( required = false ) String name,HttpServletRequest request){
        System.out.println("header2222 = " + request.getHeader("X-Request-Color-1"));
        return new BaseResponse<>(200,"Your new name is "+name,"");
    }



    //这个好像没什么用
    @GetMapping("/hello_str")
    public BaseResponse<String> sayGet(@RequestParam(required = false) String name,HttpServletRequest request){
        BaseResponse<String> stringBaseResponse = userService.sayHelloGet(name, request);
        return stringBaseResponse;
    }



    @GetMapping("/hello")
    public BaseResponse<String> sayGetList(HelloGetListParam helloGetListParam, HttpServletRequest request){
        System.out.println("helloGetListParam = " + helloGetListParam );
        BaseResponse<String> stringBaseResponse = userService.sayHelloGetList(helloGetListParam, request);
        return stringBaseResponse;
    }

    @PostMapping("/welcome")
    public BaseResponse<String> sayWelComePost(@RequestParam  String name,HttpServletRequest request){
        BaseResponse<String> stringBaseResponse = userService.sayWelcomePost(name, request);
        return stringBaseResponse;
    }
    @PostMapping("/welcome_restFul")
    public BaseResponse<String> sayWelComePostRest(@RequestBody List<InputParam> inputParam, HttpServletRequest request){
        BaseResponse<String> stringBaseResponse = userService.sayWelcomePost(inputParam, request);
        return stringBaseResponse;
    }
    @GetMapping("/welcome")
    public BaseResponse<String> sayWelComeGet(@RequestParam  String name,HttpServletRequest request){
        BaseResponse<String> stringBaseResponse = userService.sayHelloGet(name, request);
        return stringBaseResponse;
    }

    @PostMapping("/hello")
    public BaseResponse<String> sayPostReqJson(@RequestBody PostInputParamTest inputParam, HttpServletRequest request){
        System.out.println("inputParam = " + inputParam);
        BaseResponse<String> s = userService.sayHelloPost(inputParam, request);

        //调用成功，用户次数加一，创建、或者加一

        return s;

    }
}
